<?php
/**
 * 
 * Loads and keeps settings for the site as properties. It's kept as properties so it can be echoed as json.
 * All properties are loaded from the "settings" table in the database. Properties can be added statically if necessary.
 * @author martin sommervold - martin@sommervold.com
 *
 */
namespace TeamPlayers;

class Settings{
	
	/*
	 * General setings
	 */
	
	/**
	 * 
	 * The name of the organization
	 * @var string
	 */
	public $organizationName;
	
	/**
	 * 
	 * A short text describing the organization.
	 * @var string
	 */
	public $organizationDescription;
	
	/**
	 * 
	 * A link to the sites facebook page
	 * @var url
	 */
	public $facebookLink;
	
	/**
	 * 
	 * The adress to send emails to from the contact form
	 * @var string
	 */
	public $contactEmail;
	
	
	/*
	 * SMTP settings. Password should not appear here. The password should only exist when it is being committed to the database.
	 */
	
	/**
	 * 
	 * The host to send emails through. The system MUST have an smtp server in order to send emails.
	 * @var string
	 */
	public $smtpHost;
	
	/**
	 * 
	 * The username for the SMTP account
	 * @var string
	 */
	public $smtpUser;
	
	/**
	 * 
	 * The port to connect to the smtp host through, usually 25 or 587
	 * @var string
	 */
	public $smtpPort;
	
	/**
	 * 
	 * The "sender name" - appears in the from field in sendt emails
	 * @var unknown_type
	 */
	public $smtpFromField;
	
	/**
	 * 
	 * Loads and sets setting properties in this class. The settings are available through the namespace, e.g. TeamPlayers::$settings->organizationName.
	 */
	function __construct(){
		
		$sql = "SELECT * FROM settings";
		$result = TeamPlayers::$db->query($sql);
		
		while($Settings = $result->fetch_object()){
			$this->organizationName = $Settings->organizationname;
			$this->organizationDescription = $Settings->organizationdescription;
			$this->facebookLink = $Settings->facebooklink;
			$this->contactEmail = $Settings->contactemail;
			
			$this->smtpHost = $Settings->smtphost;
			$this->smtpUser = $Settings->smtpuser;
			$this->smtpPort = $Settings->smtpport;
			$this->smtpFromField = $Settings->smtpfromfield;
		}
	}
}
?>